package by.alex.dzeshko.lastfmsimple.app.fragment.sliding;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import by.alex.dzeshko.lastfmsimple.R;

import com.actionbarsherlock.app.SherlockListFragment;

public class SlideMenuFragment extends SherlockListFragment {

	private MenuCallback mCallback;
	// private ListView mListView;
	private SimpleAdapter mAdapter;

	final String ATTRIBUTE_NAME_TITLE = "title";
	final String ATTRIBUTE_NAME_IMAGE = "image";

	public SlideMenuFragment() {
	}

	@Override
	public void onAttach(Activity activity) {
		mCallback = (MenuCallback) activity;
		super.onAttach(activity);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		
		String[] titles = { "Albums", "Artists", "Tracks" };
		int[] img = { android.R.drawable.ic_media_play,
				android.R.drawable.ic_media_pause,
				android.R.drawable.ic_media_ff };

		ArrayList<Map<String, Object>> data = new ArrayList<Map<String, Object>>(
				titles.length);
		Map<String, Object> m;
		for (int i = 0; i < titles.length; i++) {
			m = new HashMap<String, Object>();
			m.put(ATTRIBUTE_NAME_TITLE, titles[i]);
			m.put(ATTRIBUTE_NAME_IMAGE, img[i]);
			data.add(m);
		}

		String[] from = { ATTRIBUTE_NAME_TITLE, ATTRIBUTE_NAME_IMAGE };
		int[] to = { R.id.row_title, R.id.row_icon };

		mAdapter = new SimpleAdapter(getSherlockActivity(), data,
				R.layout.adapter_slidemenu, from, to);

		setListAdapter(mAdapter);
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return super.onCreateView(inflater, container, savedInstanceState);
		// View rootView = inflater.inflate(R.layout.fragment_sliding_menu,
		// null);
		// mListView = (ListView)
		// rootView.findViewById(R.id.listview_slidemenu_fragment);

		// mListView.setAdapter(mAdapter);

		// return rootView;
	}

	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		mCallback.onItemSelected(position);
		super.onListItemClick(l, v, position, id);
	}

	public interface MenuCallback {
		
		public void onItemSelected(int item);
	}
}
